CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS)
CPPFLAGS=-Wall -ansi $(DEBUG) $(EXCEPTIONS) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS)
DEBUG=-O3 -g3
CMISCFLAGS=
CPPMISCFLAGS=-DGIMI_CLIENT_API=10303
DEFINITIONS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES
EXCEPTIONS=-fexceptions -ffast-math 
CINCLUDES=-I. -I../../scanmatch -I../../mcl -I$(GDIR)utils
CPPINCLUDES=-I. -I../../scanmatch -I../../mcl $(OCCU_INCLUDE) -I$(GDIR)glutImageGUI -I$(GDIR)utils \
						-I$(GIMDIR)/JPEGEncoder

LD=g++
LDFLAGS=
LIBS=-lrt -lpthread -lGL -lGLU -lglut -ljpeg

GDIR=../../../../
GIMDIR=../../../..
SRCSC=
#SRCSCPP=j2b2.cpp $(OCCU_SRC_CPP)
VPATH=
CPPGIMI=
CGIMI=

CSRCUTIL = $(GIMDIR)/utils/ownutils.c $(GIMDIR)/utils/owndebug.c
CPPIMAGEGUI = $(GIMDIR)/glutImageGUI/glutImageGUI.cpp  $(GIMDIR)/JPEGEncoder/JPEGEncoder.cpp

# Source files for dt-example
CPP_SRC_DT_EXAMPLE=dt_example.cpp $(CPPIMAGEGUI) $(OCCU_SRC_CPP)
C_SRC_DT_EXAMPLE=$(CSRCUTIL)

CPP_SRC_BETB=dtbetbloc.cpp $(OCCU_SRC_CPP) $(CPPIMAGEGUI)

#SRC_OCCU_J2B2_TEST=occu_j2b2_test.cpp $(CPPSM) $(CPPMCL) $(CPPIMAGEGUI) $(OCCU_SRC_CPP)
#CSRC_OCCU_J2B2_TEST=$(CSRCUTIL)

## Build GIMI and it's dependencies.
## Files are set to CGIMI and CPPGIMI variables
include Makefile.mcl
include $(GDIR)grid/Makefile.occu 

CGIMI += $(CMCL)
CPPGIMI += $(CPPMCL) $(CPPSM)

## Construct final lists of CPP and C objects
CPP_OBJ_DT_EXAMPLE=$(CPP_SRC_DT_EXAMPLE:.cpp=.opp)
C_OBJ_DT_EXAMPLE=$(C_SRC_DT_EXAMPLE:.c=.o)
CPP_OBJ_BETB=$(CPP_SRC_BETB:.cpp=.opp)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

all: dt_example dtbetbloc


dt_example: $(C_OBJ_DT_EXAMPLE) $(CPP_OBJ_DT_EXAMPLE)
						$(LINK) -o $@ $(C_OBJ_DT_EXAMPLE) $(CPP_OBJ_DT_EXAMPLE)
						
dtbetbloc: $(CPP_OBJ_BETB) $(C_OBJ_DT_EXAMPLE)
						$(LINK) -o $@ $(CPP_OBJ_BETB) $(C_OBJ_DT_EXAMPLE)

						
clean:
		rm -f $(C_OBJ_DT_EXAMPLE) $(CPP_OBJ_DT_EXAMPLE) *.opp *.o \
		 dt_example \
 		*.out *~ *.d *.dpp

## Compile rule for all .o (.c) file
%.o:    %.c
				$(COMPILEC) -o $@ $<

## Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
				$(COMPILECPP) -o $@ $<

## Dependency generation rule: For all required '.d' files
#%.d:	  %.c
#				$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
#				sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
#				rm -f $@.$$$$
#
## Dependency generation rule: For all required '.dpp' files
#%.dpp:	%.cpp
#				$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
#				sed 's,\($*\)\.o[ :]*,\1.opp $@ : ,g' < $@.$$$$ > $@; \
#				rm -f $@.$$$$
#
#%.h:	%.h
#
# Include dependency rules
#-include $(SRCSCPP:.cpp=.dpp) $(CPPGIMI:.cpp=.dpp)
#-include $(SRCSC:.c=.d) $(CGIMI:.c=.d)
